using System;
using System.Collections.Generic;
using System.Reflection;

namespace Pinwheel.Toolkits
{
    public static class AssemblyExtensions
    {
        public static List<T> GetAllCustomAttribute<T>(this Assembly assembly) where T : Attribute
        {
            var types = assembly.GetTypes();
            var result = new List<T>();
            foreach (var type in types)
            {
                var attrs = type.GetCustomAttributes(typeof(T), true);
                result.AddRange((T[])attrs);
            }
            return result;
        }
        
        public static List<Type> GetTypesWithCustomAttribute<T>(this Assembly assembly) where T : Attribute
        {
            var types = assembly.GetTypes();
            var result = new List<Type>();
            foreach (var type in types)
            {
                // var attrs = type.GetCustomAttributes(typeof(T), true);
                if (type.IsDefined(typeof(T), false))
                {
                    result.Add(type);
                }
            }
            return result;
        }
    }
}